package cn.finedo.common;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ReturnValueDomain<T> {
    private static final long serialVersionUID = 1L;
    private boolean success;
    private boolean fail;
    private boolean auth;
    private String resultcode = "SUCCESS";
    private String resultdesc;
    private T object;
    private List<T> list;
    private PageDomain<T> page;

    public ReturnValueDomain() {
    }

    public ReturnValueDomain(String resultcode, String resultdesc) {
        this.resultcode = resultcode;
        this.resultdesc = resultdesc;
    }

    public ReturnValueDomain(String resultcode, String resultdesc, T object) {
        this.resultcode = resultcode;
        this.resultdesc = resultdesc;
        this.object = object;
    }

    public String getResultcode() {
        return this.resultcode;
    }

    public void setResultcode(String resultcode) {
        this.resultcode = resultcode;
    }

    public String getResultdesc() {
        return this.resultdesc;
    }

    public void setResultdesc(String resultdesc) {
        this.resultdesc = resultdesc;
    }

    public T getObject() {
        return this.object;
    }

    public void setObject(T object) {
        this.object = object;
    }

    public boolean isSuccess() {
        this.success = this.resultcode.equals("SUCCESS");
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public boolean isFail() {
        this.fail = !this.resultcode.equals("SUCCESS");
        return this.fail;
    }

    public void setFail(boolean fail) {
        this.fail = fail;
    }

    public boolean isAuth() {
        this.auth = !this.resultcode.equals("AUTH_FAIL");
        return this.auth;
    }

    public void setAuth(boolean auth) {
        this.auth = auth;
    }

    public List<T> getList() {
        return this.list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public PageDomain<T> getPage() {
        return this.page;
    }

    public void setPage(PageDomain<T> page) {
        this.page = page;
    }

    @JSONField(deserialize = false)
    public ReturnValueDomain<T> setSuccess(String resultdesc) {
        this.setResultcode("SUCCESS");
        this.setResultdesc(resultdesc);
        return this;
    }

    @JSONField(deserialize = false)
    public ReturnValueDomain<T> setSuccess(String resultdesc, T object) {
        this.object = object;
        this.setResultcode("SUCCESS");
        this.setResultdesc(resultdesc);
        return this;
    }

    @JSONField(deserialize = false)
    public ReturnValueDomain<T> setSuccess(String resultdesc, List<T> list) {
        this.list = list;
        this.setResultcode("SUCCESS");
        this.setResultdesc(resultdesc);
        return this;
    }

    @JSONField(deserialize = false)
    public ReturnValueDomain<T> setSuccess(String resultdesc, PageDomain<T> page) {
        this.page = page;
        this.setResultcode("SUCCESS");
        this.setResultdesc(resultdesc);
        return this;
    }

    @JSONField(deserialize = false)
    public ReturnValueDomain<T> setFail(String resultdesc) {
        this.setResultcode("FAIL");
        this.setResultdesc(resultdesc);
        return this;
    }

    @JSONField(deserialize = false)
    public ReturnValueDomain<T> setFail(String resultdesc, T object) {
        this.object = object;
        this.setResultcode("FAIL");
        this.setResultdesc(resultdesc);
        return this;
    }
}
